package com.kingyea.mobilepolice.apimanage.camel;

import com.alibaba.fastjson.JSON;
import com.kingyea.esb.shareservice.bigdata.message.DataExchangeServiceDescript;
import com.kingyea.esb.shareservice.bigdata.message.ReqMessage;
import com.kingyea.esb.shareservice.bigdata.message.ResMessage;
import com.kingyea.esb.shareservice.bigdata.proxyinterface.ICrossBoundaryRsProxyQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description   用于测试kingyeaCamel 的状态控制
 * @date Created in 2018/9/14 23:16
 */

@RequestMapping(value = "/webservice")
@RestController
public class Controller4TestKingyeaWebservices {

    @Autowired
    private ICrossBoundaryRsProxyQueryService crossBoundaryRsProxyQueryService;
//    private CrossBoundaryRsProxyQueryServiceImpl crossBoundaryRsProxyQueryService;

    @GetMapping("hello")
    public Object hello(){
        System.out.println("hello world");
        ReqMessage reqMessage = new ReqMessage();
        reqMessage.setCode(0);
        reqMessage.setIp("127.0.0.1");
        reqMessage.setMessage("hello world");
        reqMessage.setNodeId("nodeID");
        reqMessage.setSecuredKey("key");
        reqMessage.setSenderID("1");
        reqMessage.setServiceID("2");
        reqMessage.setSequence("sequence");
        DataExchangeServiceDescript dataExchangeServiceDescript = new DataExchangeServiceDescript();
        dataExchangeServiceDescript.setServiceName("test00");
        dataExchangeServiceDescript.setData("2018-09-25 10:49:40");
        reqMessage.setServiceDescript(dataExchangeServiceDescript);
        reqMessage.setSuccess(true);
        System.out.println(reqMessage);
        ResMessage resMessage = crossBoundaryRsProxyQueryService.queryByPost(reqMessage);
        System.out.println(JSON.toJSONString(resMessage));
        return JSON.toJSONString(resMessage);
    }

    @Consumes({
            MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML
    })
    @PostMapping("/query")
    public Object queryByPost(@RequestBody ReqMessage message){
        ResMessage resMessage = crossBoundaryRsProxyQueryService.queryByPost(message);
        System.out.println(JSON.toJSONString(resMessage));
        return JSON.toJSONString(resMessage);
    }


}
